<template>
  <el-dialog
    title="题目预览"
    :visible="showDialog"
    width="60%"
    @close="btnCancel"
  >
    <el-row type="flex" justify="space-between">
      <el-col>
        【题型】：{{ questionData.questionType | formatQuestionType }}
      </el-col>
      <el-col> 【编号】：{{ questionData.id }} </el-col>
      <el-col>
        【难度】： {{ questionData.difficulty | formatDifficulty }}
      </el-col>
      <el-col> 【标签】：{{ questionData.tags }} </el-col>
    </el-row>
    <el-row type="flex" justify="space-between" style="margin-top: 20px">
      <el-col> 【学科】： {{ questionData.subjectName }} </el-col>
      <el-col> 【目录】：{{ questionData.directoryName }} </el-col>
      <el-col> 【方向】：{{ questionData.direction }} </el-col>
      <el-col> </el-col>
    </el-row>
    <hr style="margin-top: 20px" />
    <div>【题干】:</div>
    <div v-html="questionData.question" />
    <!-- 单选 -->
    <div style="padding-left: 30px" v-if="(questionData.questionType) * 1 === 1">
      <p>单选题 选项:(以下的选中项为答案)</p>
      <div v-for="item in questionData.options" :key="item.id">
        <el-radio :value="radio" :label="item.title" style="margin-top: 10px" />
      </div>
    </div>
    <!-- 多选 -->
    <div style="padding-left: 30px" v-if="(questionData.questionType) * 1 === 2">
      <p>多选题 选项:(以下的选中项为答案)</p>
      <div
        v-for="item in questionData.options"
        :key="item.id"
        style="margin-top: 10px"
      >
        <el-checkbox-group v-model="checkBox">
          <el-checkbox :label="item.title" style="margin-top: 10px" />
        </el-checkbox-group>
      </div>
    </div>
    <hr />
    【参考答案】:
    <el-button
      type="danger"
      size="small"
      @click="playVideo"
      :disabled="!questionData.videoURL"
      >视频答案解析</el-button
    >
    <br />
    <video
      style="width: 400px; height: 200px"
      v-if="showVideo"
      :src="questionData.videoURL"
      controls
    ></video>
    <hr />
    【答案解析】:
    <div style="display: inline-block" v-html="questionData.answer"></div>
    <hr />
    【题目备注】:
    <div style="display: inline-block" v-html="questionData.remarks"></div>
    <el-row slot="footer" type="flex" justify="end">
      <el-col :span="6">
        <el-button type="primary" @click="btnCancel">关闭</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import { detail } from "@/api/hmmm/questions";
import { questionType, difficulty } from "@/api/hmmm/constants";
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false,
    },
    questionId: {
      type: Number,
      required: true,
    },
  },
  filters: {
    formatQuestionType(val) {
      const obj = questionType.find((item) => item.value * 1 === val * 1);
      return obj ? obj.label : "未知";
    },
    formatDifficulty(val) {
      const obj = difficulty.find((item) => item.value * 1 === val * 1);
      return obj ? obj.label : "未知";
    },
  },
  data() {
    return {
      questionData: {}, //题目信息
      radio: "", // 单选
      checkBox: [], // 多选
      showVideo: false, // 视频显示与隐藏
    };
  },
  created() {},
  methods: {
    async getQuestionDetail(id) {
      const { data: res } = await detail({ id });
      this.questionData = res;
      console.log(this.questionData);
      if(res.questionType==='3') return
      this.radio = res.options.find((item) => item.isRight === 1).title;
      this.checkBox = res.options
        .filter((item) => item.isRight === 1)
        .map((item) => item.title);
    },

    btnCancel() {
      this.questionData = {};
      this.checkBox = [];
      this.radio = "";
      this.showVideo = false;
      this.$emit("update:showDialog", false);
    },
    playVideo() {
      if (!this.questionData.videoURL) {
        return this.$message.warning("此题目没有视频解析");
      }
      this.showVideo = true;
    },
  },
};
</script>

